<template>
  <el-dropdown @command="handleCommand" :disabled="btnDisabled">
    <el-button type="warning" v-waves icon="el-icon-download">
      <span>导出</span><i class="el-icon-arrow-down el-icon--right"></i>
    </el-button>
    <el-dropdown-menu slot="dropdown">
      <el-dropdown-item command="1">导出当前数据</el-dropdown-item>
      <el-dropdown-item command="2">导出全部数据</el-dropdown-item>
    </el-dropdown-menu>
  </el-dropdown>
</template>

<script>
  
import {
  exportExcel2Get,
  exportExcel2Post,
} from '@/api/download'

import { message } from '@/utils/base/common';

export default {
  /* 导出Excel */
  name: 'ExportExcel',
  data() {
    return {
      levelList: null
    }
  },
  props: {
    btnDisabled: Boolean,
    restPath: String,
    list: {
      type: Array,
      default: () => ([]),
    }
  },
  methods: {
    
    // 点击导出
    handleCommand(command) {
      let requestUrl = '/api/' + this.restPath
      // 导出当前数据
      if(command == 1){
        requestUrl += '/exportExcel'
        this.handleExportExcel(requestUrl)
      } 
      // 导出全部数据
      else {
        requestUrl += '/exportExcel2AllData'
        this.handleExportExcelAll(requestUrl)
      }
    },
    
    // 导出全部数据
    handleExportExcelAll(requestUrl) {
      exportExcel2Get(this, requestUrl, '')
    },

    // 导出当前数据
    handleExportExcel(requestUrl) {
      if(this.list != null){
        if(this.list.length > 0){
          exportExcel2Post(this, requestUrl, this.list)
        } else {
          message(this, 'warning', 2, '暂无数据!')
        }
      } else {
        message(this, 'warning', 2, '暂无数据!')
      }
    },

    
  }
}
</script>

<style lang="scss" scoped>
</style>
